package UDP;

import java.io.IOException;
import java.net.*;

/**
 * @author Cheng-02
 * @version V1.0
 * @Package UDP
 * @date 2024/4/17 上午11:02
 */
public class Day11_Send {
    public static void main(String[] args) {
        try {
            DatagramSocket socket = new DatagramSocket();
            String info = "你好，我是客户端";
            byte[]arr=info.getBytes();
           InetAddress addr = InetAddress.getLocalHost();
                DatagramPacket packet = new DatagramPacket(arr,arr.length, addr,8888);
                socket.send(packet);
/////////////
            DatagramSocket socket1 = new DatagramSocket(8888);
            socket1.receive(packet);
            arr = packet.getData();
            String ss = new String(arr, 0, packet.getLength());
            System.out.println(ss);

        } catch (SocketException e) {
            throw new RuntimeException(e);
        } catch (UnknownHostException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
